package org.urey.web.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.urey.dao.action.BaseAction;
import org.urey.web.service.Service;

@Controller
public class TestAction extends BaseAction {

	@Autowired
	private Service service;

	@RequestMapping(value = "/save", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void save(@RequestParam(value = "name", required = true) String name) throws Exception {
		Long result = service.save(name);
		writeString(result.toString());
	}

	@RequestMapping(value = "/get", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void get(@RequestParam(value = "id", required = false) String id) throws Exception {
		String name = service.get(id);
		writeString(name);
	}

}
